package com.hpx.javaeye.util;

import java.util.Vector;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;

public class ListCallback implements ListFieldCallback {

	private Vector listElements = new Vector();

	public void drawListRow(ListField listField, Graphics graphics, int index,
			int y, int width) {

		Bitmap bitmap = (Bitmap) listElements.elementAt(index);
		// graphics.drawText(text, 0, y, 0, width);
		// graphics.drawRoundRect(0, y, width, 20, 5, 5);
		graphics.drawBitmap(0, y, 48, 70, bitmap, 0, 0);

	}

	public Object get(ListField listField, int index) {
		return listElements.elementAt(index);
	}

	public int getPreferredWidth(ListField listField) {
		return 50;
	}

	public int indexOfList(ListField listField, String prefix, int start) {
		return listElements.indexOf(prefix, start);
	}

	public void insert(Object toInsert, int index) {
		listElements.addElement(toInsert);
	}

	public void erase() {
		listElements.removeAllElements();
	}

	private class RowManager extends Manager {

		public RowManager(Field[] rowContents) {
			super(0);
			for (int col = 0; col < rowContents.length; col++) {
				add(rowContents[col]);
			}
		}

		protected void sublayout(int width, int height) {
			// for (int col = 0; col < getFieldCount(); col++) {
			// Field curCellField = getField(col);
			// layoutChild(curCellField, _columnWidths[col],
			// getPreferredHeight());
			// setPositionChild(curCellField, getColumnStart(col), 0);
			// }
		}

	}
}
